<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/6
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="commons/header.jsp"%>
<div style="background-color: #ffffff; border-radius: 3px; padding: 12px;">
    <html>
    <head>
        <title>Title</title>
    </head>
    <body>
    <div class="container-fluid">

<%--        <div class="row">--%>
<%--            <div class="col-xs-9 col-xs-push-3">--%>
<%--                <div style="color: #0a6aa1" class="col-xs-3">--%>
<%--                    <span>今日销售额</span>--%>
<%--                    <span id="totalSales"></span>--%>
<%--                    <i class="fa fa-yen fa-5x"></i>--%>
<%--                </div>--%>
<%--                <div style="color: #0a6aa1" class="col-xs-3 col-xs-push-1">--%>
<%--                    <i class="fa fa-user-plus fa-5x"></i>&nbsp;--%>
<%--                    <span>今日新增</span>--%>
<%--                    <span  id="userNum"></span>--%>
<%--                </div>--%>
<%--            </div>--%>
<%--        </div>--%>
<%--        <hr>--%>
        <%-- 第二行:今日销售额统计报表 --%>
        <div class="row" style="width: 100%">
            <div class="col-xs-5 col-xs-push-1">
                <div id="sales" style="height: 400px;width: 100%">

                </div>
            </div>
            <%--            购物车中前十的商品报表--%>
            <div class="col-xs-5 col-xs-push-1">
                <div id="shoppingCart" style="width: 100%;height: 400px">

                </div>
            </div>
        </div>
        <hr>

        <%-- 各类商品的销售额数据报表 --%>
        <div class="row">
            <div class="col-xs-10 col-xs-push-1">
                <div id="salesShare" style="width: 100%;height: 400px" >

                </div>
            </div>
        </div>
        <hr>
        <%-- 近7天用户增长曲线统计表 --%>
        <div class="row">
            <div class="col-xs-5 col-xs-push-1">
                <div id="nearly7Days" style="width: 100%;height: 400px">

                </div>
            </div>
            <%--            近30天用户增长曲线--%>
            <div class="col-xs-5 col-xs-push-1">
                <div id="nearly30Days" style="width: 100%;height: 400px">

                </div>
            </div>


        </div>
    </div>
    </body>
    <%@include file="commons/footer.jsp"%>
    <script>

        //今日销售总额
        <%--$.ajax({--%>
        <%--    url: "${pageContext.servletContext.contextPath}/admin/totalSales",--%>
        <%--    type:"get",--%>
        <%--    dataType:"json",--%>
        <%--    success : function (msg) {--%>
        <%--        console.log(msg,"今日销售总额");--%>
        <%--        $("#totalSales").html(msg);--%>
        <%--    }--%>

        <%--});--%>

        <%-- 获取今日新增用户数的数量--%>
        <%--$.ajax({--%>
        <%--    url:"${pageContext.servletContext.contextPath}/admin/num",--%>
        <%--    type: "get",--%>
        <%--    data:{},--%>
        <%--    dataType:"json",--%>
        <%--    success: function (msg) {--%>
        <%--        $("#userNum").html(msg)--%>
        <%--        console.log(msg,"今日新增用户数");--%>
        <%--    }--%>
        <%--});--%>

        var sales = document.getElementById("sales");
        var salesCharts = echarts.init(sales);
        var option = {
            color: ['#3398DB'],
            title: {
                text: '各类商品销售额统计表',
                left: 'center',
                top: 20,
                textStyle: {
                    color: 'blue'
                }
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            xAxis: [
                {
                    type: 'category',
                    data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
                    axisTick: {
                        alignWithLabel: true
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value'
                }
            ],
            series: [
                {
                    name: '销售额',
                    type: 'bar',
                    barWidth: '30%',
                    data: [10, 52, 200, 334, 390, 330, 220]
                }
            ]
        };
        //获取分类商品的销售统计额
        $.ajax({
            url: "${pageContext.servletContext.contextPath}/admin/sale",
            async:false,
            dataType : "json",
            success: function (msg) {
                console.log(msg,"分类商品的销售额")
                var array = msg.xAxis;
                console.log(array)
                var data = [];
                for (var i = 0; i < msg.xAxis.length ;i++) {
                    data.push(msg.xAxis[i].substring(0,6))
                }


                option.xAxis[0].data = data;
                option.series[0].data = msg.series;
            }
        })
        //渲染到页面上
        salesCharts.setOption(option);


        //获取预存购物车数量前十的数据
        <%--$.ajax({--%>
        <%--    url:"${pageContext.servletContext.contextPath}/admin/getCartInfo",--%>
        <%--    type: "get",--%>
        <%--    dataType: "json",--%>
        <%--    success : function (msg) {--%>
        <%--        console.log("购物车前十的数据",msg)--%>
        <%--    }--%>
        <%--})--%>
        //购物车前十数据
        //获取到图表的元素
        var shoppingCart = document.getElementById("shoppingCart");
        //初始化图表
        var initShopCart = echarts.init(shoppingCart);
        var option1 = {
            title: {
                text: '购物车商品销售额前十排名表',
                left: 'center',
                top: 20,
                textStyle: {
                    color: 'blue'
                }
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                    type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            xAxis: {
                type: 'category',
                data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
            },
            yAxis: {
                type: 'value'
            },
            series: [{
                data: [120, 200, 150, 80, 70, 110, 130],
                type: 'bar',
                showBackground: true,
                backgroundStyle: {
                    color: 'rgba(220, 220, 220, 0.8)'
                }
            }]
        };
        $.ajax({
            url: "${pageContext.servletContext.contextPath}/admin/getCartInfo",
            async:false,
            dataType : "json",
            success: function (msg) {
                var xAxis = [];
                var series = [];
                for (var i = 0; i < msg.length; i++) {
                    //循环遍历取出横坐标及纵坐标的数组数据
                    xAxis.push(msg[i].goodId);
                    series.push(msg[i].num);
                }
                option1.xAxis.data = xAxis;
                option1.series[0].data = series;
            }
        })
        initShopCart.setOption(option1);

        <%--//今日销售总额--%>
        <%--$.ajax({--%>
        <%--    url: "${pageContext.servletContext.contextPath}/admin/totalSales",--%>
        <%--    type:"get",--%>
        <%--    dataType:"json",--%>
        <%--    success : function (msg) {--%>
        <%--        console.log(msg,"今日销售总额");--%>
        <%--        $("#totalSales").html(msg);--%>
        <%--    }--%>

        <%--})--%>




        //各类商品销售数据占比
        var salesShare = document.getElementById("salesShare");
        var initSalesShare = echarts.init(salesShare);
        var option2 = {
            title: {
                text: '各类商品销售额百分比',
                // subtext: '纯属虚构',
                left: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: '{a} <br/>{b} : {c} ({d}%)'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
                data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎']
            },
            series: [
                {
                    name: '访问来源',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: [
                        {value:100, name: '直接访问'},
                        {value: 200, name: '邮件营销'},
                        {value: 300, name: '联盟广告'},
                        {value: 400, name: '视频广告'},
                        {value: 500, name: '搜索引擎'}
                    ],
                    emphasis: {
                        itemStyle: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        $.ajax({
            url:"${pageContext.servletContext.contextPath}/admin/salesShare",
            type: "get",
            dateType:"json",
            async:false,
            success: function (msg) {
                var legend = [];
                var series = [];
                console.log("品类销售数据:",msg);
                for (var i = 0; i <msg.length ; i++) {
                    legend.push(msg[i].title.substring(0,10))
                    // legend.push(msg[i].title);
                    // series.push({value:msg[i].price,name:msg[i].title})
                    series.push({value:msg[i].price,name:msg[i].title.substring(0,10)})
                }
                option2.legend.data = legend;
                option2.series[0].data = series;
            }
        });
        initSalesShare.setOption(option2);

        //近7天增长用户数曲线
        var nearly7Days = document.getElementById("nearly7Days");
        var initNearly7Days = echarts.init(nearly7Days);
        option3 = {
            title: {
                text: '近7day用户数增长曲线'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['新增用户数']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日','zhou1']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '新增用户数',
                    type: 'line',
                    stack: '总量',
                    data: [120, 132, 101, 134, 90, 230, 210,500]
                }
            ]
        };
        $.ajax({
            url:"${pageContext.servletContext.contextPath}/admin/nearly7Days",
            type: "get",
            // dateType:"json",
            async:false,
            success :function (msg) {
                console.log("最近7天的用户增长数据",msg);
                var xAxis = [];
                var series = [];
                for (var i = 0; i < msg.length; i++) {
                    // xAxis.push(msg[i].registerDate);
                    var date = msg[i].registerDate;

                    xAxis.push(moment(date).format("MM月DD日"));
                    series.push(msg[i].totalCount);
                }
                option3.xAxis.data = xAxis;
                option3.series[0].data = series;
            }
        });
        initNearly7Days.setOption(option3);

        //近30天用户增长曲线数据
        var nearly30Days = document.getElementById("nearly30Days");
        var initNearly30Days = echarts.init(nearly30Days);

        option4 = {
            title: {
                text: '近1月用户数增长曲线'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['新增用户数']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
            },
            toolbox: {
                feature: {
                    saveAsImage: {}
                }
            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日','zhou1']
            },
            yAxis: {
                type: 'value'
            },
            series: [
                {
                    name: '新增用户数',
                    type: 'line',
                    stack: '总量',
                    data: [120, 132, 101, 134, 90, 230, 210,500]
                }
            ]
        };
        $.ajax({
            url:"${pageContext.servletContext.contextPath}/admin/nearly30Days",
            type: "get",
            dateType: "json",
            async:false,
            success :function (msg) {
                console.log("最近30天的用户增长数据",msg);
                var xAxis = [];
                var series = [];
                for (var i = 0; i < msg.length; i++) {
                    // xAxis.push(msg[i].registerDate);
                    var date = msg[i].registerDate;

                    xAxis.push(moment(date).format("MM月DD日"));
                    series.push(msg[i].totalCount);
                }
                option4.xAxis.data = xAxis;
                option4.series[0].data = series;
             }
        });

        initNearly30Days.setOption(option4);
    </script>
    </html>
</div>
<%@include file="commons/footer.jsp"%>

